package com.qzsoft.zhjd.cement.modules.cementalarm.controller;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.zhjd.cement.modules.cementalarm.dto.CementAlarmHandlerDto;
import com.qzsoft.zhjd.cement.modules.cementalarm.dto.CementAlarmListDto;
import com.qzsoft.zhjd.cement.modules.cementalarm.service.CementAlarmService;
import com.qzsoft.zhjd.common.utils.ResultUtils;

/**
 * @ClassName CementAlarmController
 * @Description 预警信息控制器
 * @author linhuawei
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/api/cementAlarm")
public class CementAlarmController {

    @Autowired
    private CementAlarmService cementAlarmService;

    /**
     * @Title page
     * @Description 获取预警信息分页列表
     * @param params 查询条件
     * @return 预警信息分页列表
     */
    @RequiresPermissions("cement:alarm:page")
    @GetMapping("/page")
    public Result<IPage<CementAlarmListDto>> page(@RequestParam Map<String, Object> params) {
        IPage<CementAlarmListDto> page = cementAlarmService.page(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title handler
     * @Description 获取预警处置信息
     * @param id 主键
     * @return 预警处置信息
     */
    @RequiresPermissions("cement:alarm:handler")
    @GetMapping("/handler/{id}")
    public Result<CementAlarmHandlerDto> handler(@PathVariable String id) {
        CementAlarmHandlerDto data = cementAlarmService.getHandlerById(id);
        return ResultUtils.ok(data);
    }

    /**
     * @Title handler
     * @Description 预警处置
     * @param dto 处置信息
     * @return 处置结果
     */
    @RequiresPermissions("cement:alarm:handler")
    @PostMapping("/handler")
    public Result<String> handler(@RequestBody CementAlarmHandlerDto dto) {
        ValidatorUtils.validateEntity(dto);
        cementAlarmService.handler(dto);
        return ResultUtils.ok();
    }
}
